@extends('member.masterCommon')
@section('content')


    <div class="row">
        <div class="col-md-12  header-wrapper" >
            <h1 class="page-header">标签管理</h1>
            <p class="page-subtitle">所有的主播都在这里</p>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <ol class="breadcrumb">
        <li><a href="{{ route('tag.index') }}">标签管理</a></li>
        <li class="active">主播标签</li>
    </ol>
    <!-- /.row -->
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <p>
                    @foreach($lives as $live)
                        <a class="btn btn-primary btn-xs" href="{{ route('tag.lives', ['live' => $live->id]) }}">{{ $live->name }}</a>
                    @endforeach
                </p>
            </div>
            <div class="row">
                <p>
                    @foreach($cates as $cate)
                        <a class="btn btn-success btn-xs" href="{{ route('tag.lives', ['cate' => $cate->cate_id]) }}">{{ $cate->cate_name }}</a>
                    @endforeach
                </p>
            </div>
            <div class="row">
                <p>
                    <a href="{{ route('lives.download', [5000]) }}" class="btn btn-default btn-xs" target="_blank"><i class="fa fa-file"></i> 导出5000条</a>
                    <a href="{{ route('lives.download', [10000]) }}" class="btn btn-default btn-xs" target="_blank"><i class="fa fa-file"></i> 导出10000条</a>
                    <a href="{{ route('lives.download', [20000]) }}" class="btn btn-default btn-xs" target="_blank"><i class="fa fa-file"></i> 导出20000条</a>
                </p>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <form>
                        <label>搜索:<input type="search" class="form-control" placeholder="" name="s" id="search" ></label>
                    </form>
                </div>
            </div>
            <table class="table table-bordered table-hover" id="dataTables-userlist">
                <thead>
                <tr>
                    <th width="100"><input type="checkbox" class="checked_all" /> </th>
                    <th>ID</th>
                    <th>主播名称</th>
                    <th>所属平台</th>
                    <th>是否在线</th>
                    <th>在线人数</th>
                    <th>所属分类</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($anchors as $anchor)
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td class="id">{{ $anchor->tag()->id }}</td>
                        <td>
                            @if($anchor->tag()->logo)
                                <img src="{{route('image', [$anchor->tag()->logo, '30x30'])}}" onerror="$(this).remove()" alt="" class="gridpic">
                            @endif
                            {{$anchor->name}}
                        </td>
                        <td><a href="{{ route('tag.lives', ['live' => $anchor->live_id]) }}">{{$anchor->live_name}}</a></td>
                        <td class="center">
                            @if ($anchor->status === 1)
                                <span class="status active">主播在线</span>
                            @else
                                <span class="status inactive">主播不在线</span>
                            @endif
                        </td>
                        <td>{{ num2word($anchor->online) }}</td>
                        <td>
                            @if ( ! empty($anchor->cate) )
                            <a href="{{ route('tag.lives', ['cate' => $anchor->cate->cate_id]) }}">
                            {{ $anchor->cate->cate_name }}
                            </a>
                            @endif
                        </td>
                        <td class="center">
                            <a href="{{route('tag.lives.edit', [$anchor->id])}}" class="btn btn-circle btn-primary ">编辑</a>
                            <a href="{{ route('anchor.preview', [$anchor->id]) }}" target="_blank" class="btn btn-circle btn-success ">预览</a>
                            @if($anchor->tag()->is_rec)
                                <a data-href="{{ route('anchors.unrec', [$anchor->id]) }}"  class="btn btn-circle btn-danger ajax-rec">取推</a>
                            @else
                                <a data-href="{{ route('anchors.rec', [$anchor->id]) }}" class="btn btn-circle btn-success ajax-rec">推荐</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="row"><div class="col-sm-6"><div class="dataTables_info" id="dataTables-userlist_info" role="status" aria-live="polite">每页显示20条数据，一共{{ $anchors->total() }}名主播，{{$online}}在线</div></div>
                <div class="col-sm-6">
                    <div class="dataTables_paginate paging_full_numbers" id="dataTables-userlist_paginate">
                        {{$anchors->links()}}
                    </div>
                </div>
            </div>
            <script>

            </script>
        </div>
    </div>
    <!-- /.row -->
@endsection

@section('scripts')
    <!-- Custom Theme JavaScript -->
    <script>

        $('.ajax-rec').on('click', function () {
            var $this = $(this);
            $.getJSON($this.data('href'), function (res) {
                layer.msg(res.msg, {icon: 1})

                if (res.msg.match("取消")) {
                    $this.data("href", $this.data('href').replace(/\/unrec/, '/rec'));
                    $this.removeClass('btn-danger').addClass('btn-success').text('推荐');
                    $this.parents('tr').find('.id').text('0')
                } else {
                    $this.data("href", $this.data('href').replace(/\/rec/, '/unrec'));
                    $this.addClass('btn-danger').removeClass('btn-success').text('取推');
                    $this.parents('tr').find('.id').text(res.id)
                }
            })
        });

        $('input[type=checkbox]').on('click', function (event) {
            if ($(event.target).hasClass('checked_all')) return ;
            $('.checked_all').prop('checked', false)}
        );

        $('.checked_all').on('click', function (event) {

            if (event.target.tagName != 'INPUT') {
                $(this).prop('checked', !$(this).prop('checked'))
            }

            $('input[type=checkbox]').prop('checked', $(this).prop('checked'))
        })
    </script>
@endsection